Repository navigation
Conversation
…ncelled `ResourceReporter.__aexit__` skipped its cleanup branch when the exit reason was `asyncio.CancelledError`, and that branch is the only place that puts the `None` sentinel the stream task waits for. `_llm_stream_report` returns only after it reads that sentinel, so a cancelled context left the task blocked on `queue.get()`: dropping `self._llm_task` does not stop a task the event loop still holds. Cancel and await the task on the cancelled path, and keep the sentinel path unchanged for a normal exit. Reachable only with `enable_llm_stream=True` (the default is False).
Author
|
About the one failing check: That is the workflow refusing to check out a fork's code rather than a result of this change - #2188 hits the same failure. Nothing to fix on my side; the other job of that matrix stays |
This branch is waiting to be deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ResourceReporter.__aexit__skipped its cleanup branch when the exit reason wasasyncio.CancelledError:That branch is the only place that puts the
Nonesentinel, and_llm_stream_reportreturns only after it reads that sentinel. So on a cancelled exit the task stayed blocked onqueue.get(). Settingself._llm_task = Nonewould not have helped either: the event loop keeps the task alive.Reproduced (in-loop observation,
enable_llm_stream=True): after the context task is cancelled and awaited, the stream task still reportsdone() == False.Change
__aexit__now always stops the task when there is one:task.cancel()and await it, swallowing its ownCancelledError;The
elsebranch keeps the previousput(None)+awaitorder, andself._llm_taskis cleared in both branches.Verification
tests/metagpt/utils/test_report.py: the cancelled-exit test fails onmain(assert Falseonstream_task.done()) and passes with the change; the normal-exit test pins that the sentinel path is unchanged (still not cancelled, still done).inner done? False cancelled? False(leak) onmain->inner done? True cancelled? True(no leak) with the patch.metagpt/_compat.pyimportssemantic_kernel.orchestration.sk_functionon Windows only, andrequirements.txtpinssemantic-kernel==0.4.3.dev0, which does not install here. The test file itself only importsmetagpt.utils.report; I ran it with a localsitecustomizestub for that module plus--confcutdir=tests/metagpt/utils(tests/conftest.pypulls in the whole provider stack). Neither workaround is part of the diff, and the Linux CI never takes the Windows branch in_compat.py.await self.async_report(None, END_MARKER_NAME)(the last line). Its behaviour is unchanged by this PR; if maintainers prefer skipping the end marker on cancellation, that is a separate decision.